複数行に打ち消し線を引くPopup Menu@0.3.0
code:script.js
var k=t=>({type:"title",text:t.rows0.text}),j=t=>{let{rows:e,...r}=t,{indent:s=0,text:n=""}=e??{},a=n.replace(/^\s*code:/,"");return{indent:s,type:"codeBlock",fileName:a,content:r.map(o=>o.text.substring(s+1)).join(` )}},l=(t,{parseOnNested:e,parseOnQuoted:r,patterns:s})=>(n,a,o)=>{var i,u,d,g,b,m;if(!e&&a.nested)return(i=o?.())!==null&&i!==void 0?i:[];if(!r&&a.quoted)return(u=o?.())!==null&&u!==void 0?u:[];for(let N of s){let h=N.exec(n);if(h===null)continue;let Q=n.substring(0,h.index),z=n.substring(h.index+((g=(d=h[0])===null||d===void 0?void 0:d.length)!==null&&g!==void 0?g:0)),T=t((b=h[0])!==null&&b!==void 0?b:"",a);return[...c(Q,a),...T,...c(z,a)]}return(m=o?.())!==null&&m!==void 0?m:[]},p=t=>[{type:"plain",raw:t,text:t}],W=l(p,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]}),I=/^>.*$/,B=(t,e)=>e.context==="table"?p(t,e):[{type:"quote",raw:t,nodes:c(t.substring(1),{...e,quoted:!0})}],L=l(B,{parseOnNested:!1,parseOnQuoted:!1,patterns:[I]}),S=/^\? .+$/,q=(t,e)=>e.context==="table"?p(t,e):[{type:"helpfeel",raw:t,text:t.substring(2)}],C=l(q,{parseOnNested:!1,parseOnQuoted:!1,patterns:[S]}),M=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,R=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,E=(t,e)=>{if(e.context==="table")return p(t,e);let r=t.substring(2,t.length-2),s=/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(r);return[{type:"strongImage",raw:t,src:s?${r}/thumb/1000:r}]},Z=l(E,{parseOnNested:!1,parseOnQuoted:!0,patterns:[M,R]}),F=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;function $(t){return(e,r)=>{if(t==="strongIcon"&&r.context==="table")return p(e,r);let s=t==="icon"?e.substring(1,e.length-1):e.substring(2,e.length-2),n=s.lastIndexOf(".icon"),a=s.substring(0,n),o=a.startsWith("/")?"root":"relative",i=s.substring(n+5,s.length),u=i.startsWith("*")?parseInt(i.substring(1),10):1;return new Array(u).fill({}).map(()=>({path:a,pathType:o,type:t,raw:e}))}}var U=$("icon"),A=l(U,{parseOnNested:!0,parseOnQuoted:!0,patterns:[F]}),P=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,_=$("strongIcon"),D=l(_,{parseOnNested:!1,parseOnQuoted:!0,patterns:[P]}),G=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,H=(t,e)=>e.context==="table"?p(t,e):[{type:"strong",raw:t,nodes:c(t.substring(2,t.length-2),{...e,nested:!0})}],J=l(H,{parseOnNested:!1,parseOnQuoted:!0,patterns:[G]}),K=/\[\$ .+? \]/,V=/\[\$ [^\]]+\]/,X=(t,e)=>e.context==="table"?p(t,e):[{type:"formula",raw:t,formula:t.substring(3,t.length-(t.endsWith(" ]")?2:1))}],Y=l(X,{parseOnNested:!1,parseOnQuoted:!0,patterns:[K,V]}),tt=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,et=(t,e)=>{if(e.context==="table")return p(t,e);let r=t.indexOf(" "),s=t.substring(1,r),n=t.substring(r+1,t.length-1),a=new Set(s);if(a.has("*")){let o=s.split("*").length-1;a.delete("*"),a.add(*-${Math.min(o,10)})}return[{type:"decoration",raw:t,rawDecos:s,decos:Array.from(a),nodes:c(n,{...e,nested:!0})}]},rt=l(et,{parseOnNested:!1,parseOnQuoted:!0,patterns:[tt]}),st=/.*?/,nt=(t,e)=>e.context==="table"?p(t,e):[{type:"code",raw:t,text:t.substring(1,t.length-1)}],at=l(nt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[st]}),ot=/^[$%] .+$/,lt=(t,e)=>{var r;if(e.context==="table")return p(t,e);let s=(r=t[0])!==null&&r!==void 0?r:"",n=t.substring(2);return[{type:"commandLine",raw:t,symbol:s,text:n}]},pt=l(lt,{parseOnNested:!1,parseOnQuoted:!1,patterns:[ot]}),it=/\[\s+\]/,ut=(t,e)=>e.context==="table"?p(t,e):[{type:"blank",raw:t,text:t.substring(1,t.length-1)}],ct=l(ut,{parseOnNested:!1,parseOnQuoted:!0,patterns:[it]}),dt=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,gt=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,ht=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,vt=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,bt=t=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(t)||mt(t),mt=t=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(t),ft=(t,e)=>{if(e.context==="table")return p(t,e);let r=t.search(/\s/),s=r!==-1?t.substring(1,r):t.substring(1,t.length-1),n=r!==-1?t.substring(r,t.length-1).trimLeft():"",[a,o]=bt(n)?[n,s]:[s,n];return[{type:"image",raw:t,src:/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(a)?${a}/thumb/1000:a,link:o}]},$t=l(ft,{parseOnNested:!0,parseOnQuoted:!0,patterns:[dt,gt,ht,vt]}),xt=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,wt=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,yt=/\[https?:\/\/[^\s\]]+\]/,Ot=/https?:\/\/[^\s]+/,Nt=(t,e)=>{if(e.context==="table")return p(t,e);let r=t.startsWith("[")&&t.endsWith("]")?t.substring(1,t.length-1):t,s=/^https?:\/\/[^\s\]]/.test(r),n=(s?/^https?:\/\/[^\s\]]+/:/https?:\/\/[^\s\]]+$/).exec(r);if(n?.[0]===void 0)return[];let a=s?r.substring(n[0].length):r.substring(0,n.index-1);return[{type:"link",raw:t,pathType:"absolute",href:n[0],content:a.trim()}]},Qt=l(Nt,{parseOnNested:!0,parseOnQuoted:!0,patterns:[xt,wt,yt,Ot]}),x=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,w=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,zt=t=>{let[e="",r="",s=""]=t.split(","),n=parseFloat(e.replace(/^N/,"").replace(/^S/,"-")),a=parseFloat(r.replace(/^E/,"").replace(/^W/,"-")),o=/^Z\d+$/.test(s)?parseInt(s.replace(/^Z/,""),10):14;return{latitude:n,longitude:a,zoom:o}},Tt=(t,e)=>{var r;if(e.context==="table")return p(t,e);let s=(r=t.match(x))!==null&&r!==void 0?r:t.match(w);if(s===null)return[];let n=t.startsWith("[N")||t.startsWith("[S"),[,a="",o=""]=n?s:[s[0],s[2],s[1]],{latitude:i,longitude:u,zoom:d}=zt(a),g=o!==""?https://www.google.com/maps/place/${encodeURIComponent(o)}/@${i},${u},${d}z:https://www.google.com/maps/@${i},${u},${d}z;return[{type:"googleMap",raw:t,latitude:i,longitude:u,zoom:d,place:o,url:g}]},kt=l(Tt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[x,w]}),jt=/\[\/?[^[\]]+\]/,Wt=t=>{let e=t.substring(1,t.length-1);return[{type:"link",raw:t,pathType:e.startsWith("/")?"root":"relative",href:e,content:""}]},It=l(Wt,{parseOnNested:!0,parseOnQuoted:!0,patterns:[jt]}),Bt=/(?:^|\s)#\S+/,Lt=(t,e)=>{if(e.context==="table")return p(t,e);if(t.startsWith("#"))return[{type:"hashTag",raw:t,href:t.substring(1)}];let r=t.substring(0,1),s=t.substring(1);return[...p(r,e),{type:"hashTag",raw:s,href:s.substring(1)}]},St=l(Lt,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Bt]}),qt=/^[0-9]+\. .*$/,Ct=(t,e)=>{if(e.context==="table")return p(t,e);let r=t.indexOf(" "),s=t.substring(0,r-1),n=parseInt(s,10),a=t.substring(r+1,t.length);return[{type:"numberList",raw:t,rawNumber:s,number:n,nodes:c(a,{...e,nested:!0})}]},Mt=l(Ct,{parseOnNested:!1,parseOnQuoted:!1,patterns:[qt]}),Rt=(t,e,r)=>{var s;return t===""?[]:(s=r?.())!==null&&s!==void 0?s:[]},Et=(...t)=>(e,r)=>t.reduceRight((s,n)=>()=>n(e,r,s),()=>W(e,r))(),c=Et(Rt,L,C,at,pt,Y,ct,rt,Z,D,J,$t,Qt,A,kt,It,St,Mt),Zt=t=>{let{rows:[e,...r]}=t,{indent:s=0,text:n=""}=e??{},a=n.replace(/^\s*table:/,"");return{indent:s,type:"table",fileName:a,cells:r.map(o=>o.text.substring(s+1)).map(o=>o.split(" ").map(i=>c(i,{nested:!1,quoted:!1,context:"table"})))}},Ft=t=>{let{indent:e,text:r}=t.rows[0];return{indent:e,type:"line",nodes:c(r.substring(e),{nested:!1,quoted:!1,context:"line"})}},Ut=t=>{switch(t.type){case"title":return k(t);case"codeBlock":return j(t);case"table":return Zt(t);case"line":return Ft(t)}},At=t=>t.split( ).map(e=>{var r,s,n;return{indent:(n=(s=(r=/^\s+/.exec(e))===null||r===void 0?void 0:r[0])===null||s===void 0?void 0:s.length)!==null&&n!==void 0?n:0,text:e}}),Pt=(t,e)=>{var r,s;return(t.type==="codeBlock"||t.type==="table")&&e.indent>((s=(r=t.rows[0])===null||r===void 0?void 0:r.indent)!==null&&s!==void 0?s:0)},f=(t,e)=>{let r=t[t.length-1];return r!==void 0&&Pt(r,e)?(r.rows.push(e),t):(t.push({type:/^\s*code:/.test(e.text)?"codeBlock":/^\s*table:/.test(e.text)?"table":"line",rows:[e]}),t)},_t=(t,e)=>{var r;if(!((r=e.hasTitle)!==null&&r!==void 0)||r){let[s,...n]=t;return s===void 0?[]:[{type:"title",rows:[s]},...n.reduce(f,[])]}return t.reduce(f,[])},y=(t,e)=>{var r;let s=At(t);return _t(s,{hasTitle:(r=e?.hasTitle)!==null&&r!==void 0?r:!0}).map(Ut)};var O=t=>y(t,{hasTitle:!1}).flatMap(r=>{switch(r.type){case"title":return[];case"codeBlock":return Dt(r);case"table":return Gt(r);case"line":return Ht(r)}}).map(r=>r).join(
),Dt=({fileName:t,content:e,indent:r})=>{let s=" ".repeat(r);return[${s}code:${t},...e.split(
).map(n=>${s} ${n})]},Gt=({fileName:t,cells:e,indent:r})=>{let s=" ".repeat(r);return[${s}table:${t},...e.map(n=>${s} ${n.map(a=>a.map(o=>o.raw).join("")).join(" ")})]},Ht=({nodes:t,indent:e})=>[${" ".repeat(e)}${t.map(r=>${v(r)}).join("")}],v=t=>{switch(t.type){case"quote":return> ${t.nodes.map(e=>v(e)).join("")};case"helpfeel":return-? ${t.text};case"commandLine":return-${t.symbol} ${t.text};case"icon":case"strongIcon":case"image":case"strongImage":case"formula":case"code":case"googleMap":return t.raw;case"strong":return${t.nodes.map(e=>v(e)).join("")};case"decoration":{t.decos.includes("-")||t.decos.push("-");let e=t.decos.map(r=>{let s=parseInt(r.match(/\*-(\d)/)?.[1]??"0");return s>0?"*".repeat(s):r}).join("");return[${e?${e} :""}${t.nodes.map(r=>v(r)).join("")}]}case"link":switch(t.pathType){case"root":case"relative":return${t.href};case"absolute":return[- ${t.content?${t.content} :""}${t.href}]]}case"hashTag":return#${t.href};case"numberList":return${t.number}. ${t.nodes.map(e=>v(e)).join("")};case"blank":case"plain":return${t.text}`}};scrapbox.PopupMenu.addButton({title:"打消し",onClick:t=>{let e=O(t);if(t!==e)return e}});